package com.peng.ivos.vehicle.controller;

import com.peng.ivos.base.response.JsonResult;
import com.peng.ivos.vehicle.pojo.dto.VehicleQuery;
import com.peng.ivos.vehicle.pojo.dto.VehicleRepairSaveParam;
import com.peng.ivos.vehicle.pojo.dto.VehicleSaveParam;
import com.peng.ivos.vehicle.pojo.vo.VehicleVO;
import com.peng.ivos.vehicle.service.VehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/vehicle")
@Api(tags = "车辆管理")
public class VehicleController {
    @Autowired
    VehicleService vehicleService;

    @GetMapping("/select")
    @ApiOperation("查询车辆列表")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery){
        log.debug("查询车辆:vehicleQuery={}",vehicleQuery);
        return vehicleService.getVehicleList(vehicleQuery);
    }

    @GetMapping("/select/{id}")
    @ApiOperation("查询围栏内可用车辆详情")
    public JsonResult selectVehicleWithAvailable(@PathVariable("id") Long id){
        log.debug("查询围栏内车辆和可用:id={}",id);
        return vehicleService.getVehicleListWithAvailable(id);
    }

   @PostMapping("/save")
   @ApiOperation("保存车辆信息")
   public JsonResult saveVehicle(VehicleSaveParam vehicleSaveParam){
        log.debug("保存车辆参数:vehicleSaveParam={}",vehicleSaveParam);
        return vehicleService.saveVehicle(vehicleSaveParam);
   }

   @PostMapping("/delete/{id}")
   @ApiOperation("删除车辆")
   public JsonResult deleteVehicle(@PathVariable Long id){
        return vehicleService.deleteVehicle(id);
   }

   @PostMapping("/unbind/{vehicleId}")
    public JsonResult unbindVehicle(@PathVariable Long vehicleId){
        log.debug("解绑车辆:vehicleId={}",vehicleId);
        return vehicleService.removeBindVehicle(vehicleId);
   }

    @PostMapping("/bind/{geofenceId}/{vehicleId}")
    @ApiOperation("绑定车辆")
    public JsonResult bindVehicle(@PathVariable Long geofenceId,@PathVariable Long vehicleId){
        log.debug("绑定车辆:geofenceId={},vehicleId={}",geofenceId,vehicleId);
        return vehicleService.addBindVehicle(geofenceId,vehicleId);
    }

    @GetMapping("/select/repairList")
    @ApiOperation("查询维修车辆列表")
    public JsonResult selectRepairCarListByPage(VehicleQuery vehicleQuery){
        log.debug("查询维修车辆:vehicleQuery={}",vehicleQuery);
        return vehicleService.getRepairCarListByPage(vehicleQuery);
    }

    @GetMapping("/select/repair/{repairId}")
    public JsonResult selectRepairCarByRepairId(@PathVariable String repairId){
        log.debug("根据维修单id查询维修单信息:repairId={}",repairId);
        return vehicleService.getRepairCarByRepairId(repairId);
    }

    @GetMapping("/getAllVehicleLicense")
    @ApiOperation("查询已注册车辆车牌号")
    public JsonResult getAllVehicleLicense(){
        return vehicleService.getAllVehicleLicense();
    }

    @PostMapping("/save/repair")
    public JsonResult saveRepairVehicle(VehicleRepairSaveParam vehicleRepairSaveParam){
        log.debug("保存维修车辆:vehicleRepairSaveParam={}",vehicleRepairSaveParam);
        return vehicleService.saveRepairVehicle(vehicleRepairSaveParam);
    }

    @DeleteMapping("/delete/repair/{repairId}")
    public JsonResult deleteRepairVehicle(@PathVariable Long repairId){
        log.debug("删除维修车辆:repairId={}",repairId);
        return vehicleService.deleteRepairVehicle(repairId);
    }
}
